package com.yty.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yty.system.config.Producer;
import com.yty.system.entity.vo.ProducerVo;
import com.yty.system.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    Producer producer;

    @Value("${rocketmq.topic}")
    private String TOPIC;

    @Override
    public void sendMessage() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","李冰薇");
        jsonObject.put("sex","女");
        jsonObject.put("age","24");
        ProducerVo producerVo = new ProducerVo();
        producerVo.setTopic(TOPIC)
                .setTag(UUID.randomUUID().toString())
                .setKey("admin").setData(JSONObject.toJSONString(jsonObject))
                .setSendTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        producer.syncSend(producerVo);
    }
}
